#ifndef OCTREEHOLDER_H
#define OCTREEHOLDER_H

// This class holds the information about the masses in the simulation.
// This class provides access to each body and computes the
// accelleration.

// All details about how the masses are stored or how the acceleration
// is calculated are abstracted in the private functions.

// Masses may be accessed using brackets, and this class can be used 
// like a tree. This does not necessarily mean this is how the masses
// are actually being stored.

#include "Body.h"
#include "macros.h"
#include "ParamHolder.h"
#include "vec.h"

#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

class OctreeHolder
{
   public:
      OctreeHolder();
      OctreeHolder(double);
      OctreeHolder(string,ParamHolder*);
      OctreeHolder(double[], double);
      ~OctreeHolder();
	  
      void readFromFile(string);
      void writeToFile(string);

      void addBody(Body*);
      OctreeHolder* check_pos(Body*);

      void rebuildTree();
      Body* getBody(int);
      Body* getTopBody();

      int size();
      void centerSystem();

      vec force(Body*);
      vec accel(int);

      double getLength();
      double getMass();
      void setParams(ParamHolder*);

   private:
      Body* body;
      double center[3];
      double centerOfMass[3];

      OctreeHolder* children[8];
      double mass, length;
      int nBodies;
	  
      ParamHolder* params;

      string prepLine(string);

      double getNum(string s);
      string rmFirstNum(string s);
};

#endif //OCTREEHOLDER_H
